import React, { PureComponent } from 'react';
import {
  Form,
  Modal,
  Drawer,
} from 'antd';

import StandardTable from '@/components/StandardTable';
import { connect } from 'dva';

@connect(({ Invite, loading }) => ({
  Invite,
  loading: loading.models.Invite,
}))
class DescView extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      userList: [],
    };
  }

  componentWillReceiveProps(nextProps) {
    const { userList } = this.props;
    this.setState({
      userList,
    });
    // dispatch({
    //   type: 'platuser/userList',
    //   payload: {
    //     userNo: nextProps.userNo,
    //   },
    // });
  }

  handleStandardTableChange = (pagination, filtersArg, sorter) => {
    const { dispatch, selectedRows } = this.props;
    const { formValues } = this.state;
    this.setState({
      pagination: {
        pageNo: pagination.current,
        pageSize: 15,
      },
    });
    const params = {
      pageNo: pagination.current,
      pageSize: pagination.pageSize,
      ...formValues,
      userNo: selectedRows.userNo,
    };

    dispatch({
      type: 'platuser/userList',
      payload: params,
    });
  };

  render() {
    const { lookDescView, handleLookDesc, userList } = this.props;
    const columns = [
      {
        title: '用户编号',
        dataIndex: 'userNo',
        key: 'userNo',
      },
      {
        title: '注册时间',
        dataIndex: 'regTime',
        key: 'regTime',
      },
      {
        title: '首次出借时间',
        dataIndex: 'borrowTime',
        key: 'borrowTime',
      },
      {
        title: '是否出借',
        dataIndex: 'borrow',
        key: 'borrow',
        render(val) {
          return <div>{val ? '是' : '否'}</div>;
        },
      },
      {
        title: '是否实名',
        dataIndex: 'account',
        key: 'account',
        render(val) {
          return <div>{val ? '是' : '否'}</div>;
        },
      },
      {
        title: '实名时间',
        dataIndex: 'accountTime',
        key: 'accountTime',
      },
    ];
    return (
      <Drawer
        destroyOnClose
        title="邀请用户列表"
        width={700}
        visible={lookDescView}
        closable={false}
        onClose={() => handleLookDesc(false, [])}>
        <StandardTable
          data={userList}
          selectedRows={[]}
          rowKey={'userNo'}
          rowSelectHide={true}
          columns={columns}
          onChange={this.handleStandardTableChange}
        />

      </Drawer>
    );
  }
}

export default DescView;

